/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package horizon.map;

import horizon.collision.CollisionManager;
import horizon.component.IRenderUpdate;
import horizon.entity.Entity;
import horizon.graphics.RenderingContext;
import horizon.util.Vector2;
import java.util.HashMap;

public class Map implements IRenderUpdate{

    public static int tileSize = 64;
    public static int tileSide = 10;
    public static int chunkSide = 10;
    public CollisionManager collision;
    ResourceMap resources = new ResourceMap();
    HashMap<Vector2, Chunk> chunks = new HashMap<Vector2, Chunk>();
    public Vector2 size;

    public Map() {

        size = new Vector2(640, 640);
        collision = new CollisionManager(this);
    }

    public void addChunk(Chunk c, Vector2 orientation) {

        chunks.put(orientation, c);

    }

    public void render(RenderingContext r) {

        
  
       for(Chunk c : chunks.values()){
           
           c.render(r);
           
           
       }

      
        collision.render(r);
    }
    @Override
    public void update(long elapsedTime) {
        
        collision.update(elapsedTime);
        
    }
    

    public Chunk getChunk(Vector2 pos) {

        Vector2 c = pos.div((float) tileSize).div(tileSide);
        return chunks.get(c);

    }
    
    public Entity getEntity(String s){
        
        return collision.getEntity(s);
        
    }

    public void addEntity(Entity e) {

        collision.addEntity(e);

    }

    public void removeEntity(String id) {

        collision.removeEntity(id);

    }

    public HashMap<Vector2, Chunk> getChunks() {
        
        return chunks;
        
    }
    
     public HashMap<String, Entity> getEntities(){
         
         return collision.getEntities();
         
     }
    
    
    
}
